﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.ComponentModel;

namespace CodeCounsel.SharePoint.Flash
{
    [ToolboxData("<{0}:FlashVideoWebPart runat=server></{0}:FlashVideoWebPart>")]
    public class FlashVideoWebPart 
        : WebPart
    {
        FlashVideo _videoControl;

        [DefaultValue(640),
        WebBrowsable,
        WebDescription("The width of the video area"),
        WebDisplayName("Video Width"),
        Personalizable(PersonalizationScope.User),
        Category("Flash")]
        public int VideoWidth
        {
            get 
            {
                EnsureChildControls();
                return _videoControl.VideoWidth;
            }
            set
            {
                EnsureChildControls();
                _videoControl.VideoWidth = value;
            }
        }

        [DefaultValue(480),
        WebBrowsable,
        WebDescription("The height of the video area"),
        WebDisplayName("Video Height"),
        Personalizable(PersonalizationScope.User),
        Category("Flash")]
        public int VideoHeight
        {
            get
            {
                EnsureChildControls();
                return _videoControl.VideoHeight;
            }
            set
            {
                EnsureChildControls();
                _videoControl.VideoHeight = value;
            }
        }


        [DefaultValue(""),
        WebBrowsable,
        WebDescription("The video to display"),
        WebDisplayName("Video Source"),
        Personalizable(PersonalizationScope.Shared),
        Category("Flash")]
        public string VideoSource
        {
            get
            {
                EnsureChildControls();
                return _videoControl.VideoSource;
            }
            set
            {
                EnsureChildControls();
                _videoControl.VideoSource = value;
            }
        }


        [DefaultValue(false),
        WebBrowsable,
        WebDescription("Auto-start the video on page load."),
        WebDisplayName("Auto Start"),
        Personalizable(PersonalizationScope.Shared),
        Category("Flash")]
        public bool AutoStart
        {
            get 
            {
                EnsureChildControls();
                return _videoControl.AutoStart;
            }
            set
            {
                EnsureChildControls();
                _videoControl.AutoStart = value;
            }
        }

        [DefaultValue(""),
        WebBrowsable,
        WebDescription("The image to display when the video is loading."),
        WebDisplayName("Preview Image Location"),
        Personalizable(PersonalizationScope.Shared),
        Category("Flash")]
        public string PreviewImageUrl
        {
            get 
            {
                EnsureChildControls();
                return _videoControl.PreviewImageUrl;
            }
            set
            {
                EnsureChildControls();
                _videoControl.PreviewImageUrl = value;
            }
        }

        [DefaultValue(true),
        WebBrowsable,
        WebDescription("Show the play icon in the middle of the display."),
        WebDisplayName("Show Icons"),
        Personalizable(PersonalizationScope.Shared),
        Category("Flash")]
        public bool ShowIcons
        {
            get 
            {
                EnsureChildControls();
                return _videoControl.ShowIcons;
            }
            set
            {
                EnsureChildControls();
                _videoControl.ShowIcons = value;
            }
        }

        [DefaultValue(true),
        WebBrowsable,
        WebDescription("How to display videos in full-screen mode"),
        WebDisplayName("Fullscreen Mode"),
        Personalizable(PersonalizationScope.Shared),
        Category("Flash")]
        public FullScreenMode FullScreenMode
        {
            get 
            {
                EnsureChildControls();
                return _videoControl.FullScreenMode;
            }
            set
            {
                EnsureChildControls();
                _videoControl.FullScreenMode = value;
            }
        }

        public override ControlCollection Controls
        {
            get
            {
                EnsureChildControls();
                return base.Controls;
            }
        }

        protected override void CreateChildControls()
        {
            _videoControl = new FlashVideo();
            Controls.Add(_videoControl);
            ChildControlsCreated = true;
        }
    }
}
